package com.itheima.controller;

import com.itheima.common.MenuReqDto;
import com.itheima.entity.Zuigao;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menus")
public class MenuController {
    @Autowired
    private PermissionService permissionService;
    @PutMapping("/{id}")
    @Transactional
    public void modifyMenu(@RequestBody MenuReqDto menuReqDto){
        permissionService.modify(menuReqDto);
    }
    @GetMapping
    public List<Zuigao> findAllMenu(){
        return  permissionService.findAll();
    }
    @GetMapping("/{id}")
    public MenuReqDto findMenu(Long id){
       return permissionService.findMenu(id);
    }
    @DeleteMapping("/{id}")
    @Transactional
    public void deleteById(@PathVariable Long id){
        permissionService.deleteById(id);
    }
    @PostMapping
    public MenuReqDto add(@RequestBody MenuReqDto menuReqDto){
       return permissionService.add(menuReqDto);
    }
}
